<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.hotel.entity.BookidType" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="js/calendar.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/hotel/style/style.css"></link>
    <style type="text/css">
        body {
            margin: 0;
            padding: 0;
            font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(to right, #e0f7fa, #80deea);
        }

        #container {
            max-width: 900px;
            margin: 0 auto;
            padding: 20px;
        }

        #content {
            padding: 20px 0;
            display: flex;
            justify-content: center;
        }

        table {
            width: 100%;
            max-width: 800px;
            border-collapse: collapse;
            background-color: #ffffff;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            border-radius: 8px;
            overflow: hidden;
            font-size: 0.95em;
        }

        caption {
            padding: 20px 0;
            font-size: 1.5em;
            font-weight: bold;
            text-align: center;
            color: #006064;
        }

        th, td {
            border: 1px solid #b0bec5;
            padding: 12px 15px;
            text-align: center;
            vertical-align: middle;
        }

        th {
            background-color: #00838f;
            color: white;
            font-weight: bold;
        }

        td {
            color: #333;
        }

        .type {
            width: 150px;
        }

        .price {
            width: 120px;
        }

        .introduce {
            text-align: left;
            padding-left: 15px;
        }

        #content div.button {
            text-align: center;
            padding-top: 15px;
        }

        hr {
            margin-top: 40px;
            border: none;
            border-top: 1px solid #ccc;
        }

        #footer {
            text-align: center;
            padding: 20px;
            font-size: 0.9em;
            color: #666;
        }

        .subcontent {
            background-color: #ffffff;
            padding: 25px 30px;
            border-radius: 10px;
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
            max-width: 600px;
            margin: 0 auto;
        }

        .subcontent form fieldset {
            border: none;
            margin-bottom: 20px;
        }

        .subcontent form legend {
            font-size: 1.3em;
            font-weight: 600;
            color: #00796b;
            margin-bottom: 15px;
            border-bottom: 2px solid #004d40;
            padding-bottom: 5px;
            width: fit-content;
        }

        .subcontent form div {
            margin-bottom: 15px;
            display: flex;
            align-items: center;
        }

        .subcontent form label {
            width: 100px;
            font-weight: 600;
            color: #004d40;
        }

        .subcontent form input[type="text"] {
            flex: 1;
            padding: 8px 12px;
            border: 1px solid #b2dfdb;
            border-radius: 6px;
            font-size: 1em;
            transition: border-color 0.3s ease;
        }

        .subcontent form input[type="text"]:focus {
            border-color: #00796b;
            outline: none;
            box-shadow: 0 0 6px rgba(0,121,107,0.4);
        }

        fieldset.buttons {
            text-align: center;
        }

        fieldset.buttons input[type="submit"],
        fieldset.buttons input[type="button"] {
            background-color: #00796b;
            color: white;
            font-weight: 600;
            padding: 10px 25px;
            border: none;
            border-radius: 25px;
            cursor: pointer;
            font-size: 1.1em;
            transition: background-color 0.3s ease;
        }

        fieldset.buttons input[type="submit"]:hover {
            background-color: #004d40;
        }
        fieldset.buttons input[type="button"]:hover {
            background-color: #004d40;
        }

    </style>

    <title>预定图书</title>
</head>
<body>
<div id="container">
    <div id="header">
        <ul>
            <li><a href="#">帮助</a></li>
        </ul>
    </div>
    <div id="menu">
        <ul>
            <li><a href="<%=request.getContextPath()%>/hotel/index.jsp">首页</a></li>
            <li><a href="<%=request.getContextPath()%>/list.book">图书列表</a></li>
            <li><a href="<%=request.getContextPath()%>/list.subscription">会员中心</a></li>
        </ul>
    </div>
    <div id="content" style="width:98%; position:relative;">
        <div class="submenu">
            <ul>
                <li><a href="<%=request.getContextPath()%>/list.subscription">图书预订</a></li>
                <li><a href="<%=request.getContextPath()%>/list.hsubscription">历史订单</a></li>
                <li><a href="<%=request.getContextPath()%>/editMember.member">修改信息</a></li>
                <li><a href="<%=request.getContextPath()%>/hotel/editPassword.jsp">修改密码</a></li>
                <li><a href="<%=request.getContextPath()%>/hotel/index.jsp">退出系统</a></li>
            </ul>
        </div>
        <div class="subcontent">
            <p>下面是满足您预订条件的图书，请选择一个或多个然后点击完成按钮，点击上一步可以更改预定条件。</p>
            <form action="<%=request.getContextPath()%>/createSubscriptionDetails.member" method="post" onsubmit="return validateSelection()">
                <%
                    List<BookidType> availableBookids = (List<BookidType>) request.getAttribute("availableBookids");
                    if (availableBookids != null && !availableBookids.isEmpty()) {
                %>
                <table border="1">
                    <tr>
                        <th>选择</th>
                        <th>图书编号</th>
                    </tr>
                    <% for (BookidType bookid : availableBookids) { %>
                    <tr>
                        <td><input type="checkbox" name="selectedBookids" value="<%= bookid.getNo() %>"/></td>
                        <td><%= bookid.getNo() %></td>
                        <input type="hidden" name="startDate_<%= bookid.getNo() %>" value="<%= bookid.getStartDate() %>"/>
                        <input type="hidden" name="endDate_<%= bookid.getNo() %>" value="<%= bookid.getEndDate() %>"/>
                    </tr>
                    <% } %>
                </table>
                <%
                } else {
                %>
                <p>没有可用图书。</p>
                <%
                    }
                %>
                <div style="text-align:center;">
                    <fieldset class="buttons">
                        <input type="button" value="返回" onclick="goBack()">

                        <script>
                            function goBack() {
                                window.history.back();
                            }

                            function validateSelection() {
                                const checkboxes = document.getElementsByName("selectedBookids");
                                let isChecked = false;

                                for (let i = 0; i < checkboxes.length; i++) {
                                    if (checkboxes[i].checked) {
                                        isChecked = true;
                                        break;
                                    }
                                }

                                if (!isChecked) {
                                    alert("请至少选择一本图书");
                                    return false;
                                }
                                return true;
                            }
                        </script>

                        <input type="submit" value="完成"/>
                        <fieldset class="buttons">
                </div>
            </form>
        </div>
    </div>
    <hr />
    <div id="footer">
    </div>
</div>
</body>
</html>